/* 
    Squirrel open project
    Copyright (C) 2012  Elias Aran Paul Farhan
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#include <utility/xmlreader.hpp>
Character* XML2char(const char* filename)
{
	TiXmlDocument doc(filename);
	if (!doc.LoadFile())
		return NULL;

	TiXmlHandle hDoc(&doc);
	TiXmlElement* pElem;
	TiXmlHandle hRoot(0);
	std::string name;
	Point pos;
	Point size;
	// block: name, pos, size
	{
		pElem=hDoc.FirstChildElement().Element();
		// should always have a valid root but handle gracefully if it does
		if (!pElem) 
			return NULL;
		name=(pElem->FirstAttribute()->Value());
		std::cout << name << std::endl;
		pos = string2point(pElem->FirstAttribute()->Next()->Value());
		std::cout << pos.first << ' '<< pos.second << std::endl;
		size = string2point(pElem->FirstAttribute()->Next()->Next()->Value());
		std::cout << size.first<<' '<<size.second << std::endl;
		// save this for later
		hRoot=TiXmlHandle(pElem);
	}
	Character* character = new Character(name, pos, size);
	//block : states and boxes
	{
		pElem=hDoc.FirstChildElement().FirstChildElement().FirstChildElement().Element();
	}

	return character;

}
